package utfpr.ct.dainf.engcomp.logica;

import java.util.Random;

import utfpr.ct.dainf.engcomp.bean.Cromossomo;
import utfpr.ct.dainf.engcomp.bean.Gene;

public class Ambiente {
	
	int[] peso = {3, 5, 7, 2, 8, 4, 4, 3, 7, 2, 3, 5, 4, 3};
	int[] valor = {5, 2, 3, 8, 9, 3, 2, 4, 5, 1, 2, 6, 3, 2};
	final int MAX_GERACOES = 500;
	final int MAX_POP = 100;
	final int MAX_GENES = 14;
	final static int MAX_PESO = 25;
	
	public Ambiente(){
		this.criarPopulacao(MAX_POP, MAX_GENES);
	}
	
	private void criarPopulacao(int totalPopulacao, int genesCromossomo){
		Cromossomo[] cromossomo = new Cromossomo[totalPopulacao];
		FitnessFunction fitness = new FitnessFunction(valor, peso);
		for(int i=0; i<totalPopulacao; i++){
			cromossomo[i] = new Cromossomo(MAX_GENES);
			for(int j=0; j<genesCromossomo; j++){
				cromossomo[i].setGeneAt(j, new Gene(new Random().nextInt(2)));
			}
		}
		Populacao populacao = new Populacao(cromossomo, fitness);
		
		while( populacao.getGeracao() < MAX_GERACOES ){
			populacao.evoluir();
		}
		System.out.println("Fim Geracao "+fitness.getGeracao()+" Valor: "+fitness.getValor()+" Peso: "+fitness.getPeso());
	}
	
}
